package com.atguigu.crud.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.atguigu.crud.bean.Department;
import com.atguigu.crud.bean.Msg;
import com.atguigu.crud.service.DepartmentService;

/**
 * 处理和部门有关的请求
 * @author lfy
 *
 */
@Controller
public class DepartmentController {
	
	@Autowired
	private DepartmentService departmentService;
	
	/**
	 * 返回所有的部门信息
	 */
	//@RequestMapping("/depts")
	@RequestMapping("/deptin")
	@ResponseBody
	public Msg getDepts(){
		//查出的所有部门信息
		List<Department> list = departmentService.getDepts();
		return Msg.success().add("depts", list);
	}
	/*
	 * 根据id查询
	 */
	@RequestMapping("/deptid/{id}")
	@ResponseBody
	public Msg getDeptId(@PathVariable("id")Integer id){
		//查出的所有部门信息
		Department deptid = departmentService.getDeptId(id);
		return Msg.success().add("depts", deptid);
	}
	/*
	 *根据id和name查询 
	 */
	@RequestMapping(value="/deptin/{deptId},{deptName}",method=RequestMethod.GET)
	@ResponseBody
	public Msg getDeptIdAndName(@PathVariable("deptId")Integer deptId,@PathVariable("deptName")String deptName){
		//查出的所有部门信息
		Department deptid = departmentService.getDeptIdAndName(deptId, deptName);
		return Msg.success().add("depts", deptid);
	}

}
